package model;


import java.util.HashMap;
import java.util.Map;

import model.Address;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

public class User {
	private long id;
	private transient String username; 
	private transient String password;
	private String name;  
	private String email;
	private String phone;
	private String gender;
	private String bulletin;
	private String accountType;
	private Map<Long, Address> addresses = new HashMap<Long, Address>();
	

	public User(long id,String username, String password, String name, String email,
			String phone, String gender,  String bulletin, String accountType) {
		super();
		this.id = id;
		this.username = username;
		this.password = password;
		this.name = name;
		this.email = email;
		this.phone = phone;
		this.gender = gender;
		setBulletin(bulletin);
		this.accountType = accountType;
		
	}
	
	public void addAddress(Address address){
		this.addresses.put(address.getId(), address);
	}

	/**
	 * @return the id
	 */
	public long getId() {
		return id;
	}

	public void setId(long id){
		this.id = id;
	}


	/**
	 * @return the accountType
	 */
	public String getAccountType() {
		return accountType;
	}

	private void setBulletin(String bulletin){
		if(bulletin==null){
			this.bulletin = "N";
		}else{
			this.bulletin = "Y";
		}
	}
	private static String capitalize(String line)
	{
		String lineInLowerCase = line.trim().toLowerCase();
	    return Character.toUpperCase(lineInLowerCase.charAt(0)) + lineInLowerCase.substring(1);
	}
	/**
	 * @param city the city to set
	


	/**
	 * @return the username
	 */
	public String getUsername() {
		return username;
	}
	/**
	 * @return the password
	 */
	public String getPassword() {
		return password;
	}
	/**
	 * @return the name
	 */
	public String getName() {
		return name;
	}
	/**
	 * @return the email
	 */
	public String getEmail() {
		return email;
	}
	/**
	 * @return the phoneNumber
	 */
	public String getPhone() {
		return phone;
	}
	/**
	 * @return the gender
	 */
	public String getGender() {
		return gender;
	}
	
	/**
	 * @return the bulletin
	 */
	public String getBulletin() {
		return bulletin;
	}



	public static String getUserJson(User user){
		Gson gson = new GsonBuilder().serializeNulls().create();
		String json = gson.toJson(user); 
		return json;
	}
	
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + (int) (id ^ (id >>> 32));
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		User other = (User) obj;
		if (id != other.id)
			return false;
		return true;
	}
}
